package com.stars.home.vmodel

import android.app.Application
import android.text.TextUtils
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.stars.home.fragment.AccountBillFragment
import com.stars.home.model.AmountCount
import com.stars.home.model.User
import com.stars.home.utils.TimeUtils
import com.stars.home.utils.net.NetEngine
import com.tencent.mmkv.MMKV
import com.trailer.base.base.BRRepository
import com.trailer.base.base.BRViewModel
import com.trailer.base.net.IResp
import kotlinx.coroutines.launch

/**
 *
 *on 2020/9/18
 */
class HomeListVModel(application: Application) : BRViewModel<BRRepository>(application) {


    var status:String?="-1"
    var index=MutableLiveData<Int>()



    fun toRefuse(id:String?,position:Int?){

        toSetReceiving(id,"-1",position)

    }

    fun toReceiving(id:String?,serviceTime:String?,position:Int?){

        var isRecord= MMKV.defaultMMKV().getString("isRecord","4")
        if(isRecord.equals("0")){
            toast("您还为认证！，无法接单！")
            return
        }
        if(isRecord.equals("1")){
            toast("实名认证信息审核中暂时不能接单！请等待")
            return
        }
        if(isRecord.equals("-1")){
            toast("实名认证信息审核不通过！")
            return
        }
        if(isRecord.equals("3")){
            toast("请开启接单按钮！")
            return
        }

        if(TimeUtils.timeCompare(serviceTime,TimeUtils.getTime())==3){
          toast("已超过预约时间，无法接单！")
            return
        }
        toSetReceiving(id,"1",position)

    }

    fun toSetReceiving(id:String?,type:String?,position:Int?){

        viewModelScope.launch {
            var it=repository().lreq { NetEngine.service.receiving(id,type) }
            if(it.ok(true)){
                index.value=position
            }
        }

    }




    override fun apiFunc(): suspend () -> IResp<*> {


        return {
            NetEngine.service.technicianOrder(10, repository().page,status,"0","0")
        }
    }
}
